package com.gitee.target123.develop.login;

import com.gitee.target123.develop.login.properties.JustAuthProperties;
import com.gitee.target123.develop.login.util.AuthRequestFactory;
import me.zhyd.oauth.cache.AuthStateCache;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration
@Import({JustAuthStateCacheConfiguration.Default.class,
         JustAuthStateCacheConfiguration.Redis.class,
         JustAuthStateCacheConfiguration.Custom.class})
@EnableConfigurationProperties(JustAuthProperties.class)
public class JustAuthAutoConfiguration {

    @Bean
    @ConditionalOnProperty(prefix = "justauth", value = "enabled", havingValue = "true")
    public AuthRequestFactory authRequestFactory(JustAuthProperties properties, AuthStateCache authStateCache) {
        return new AuthRequestFactory(properties, authStateCache);
    }

}
